const mongoose = require('mongoose');
const shortid = require('shortid');
const moment = require('moment');


const ReplySchema = new mongoose.Schema({

    _id:{
        type:String,
        default:shortid.generate,
        unique:true,
    },
    content:{
        type:String
    },
    king_id:{
        type:String,
        ref:'Buller'
    },
    good_id:{
        type:String,
        ref:'Good'
    },
    desc_id:{
        type:String,
        ref:'desc'
    },

    create_time:{
        type:Date,
        default:Date.now
    },



})
ReplySchema.statics = {
    getReplysByGood:(good_id,callback)=>{
        Reply.find({'good_id':good_id}).populate('desc_id').populate('king_id').sort({'create_time':-1}).then((replys)=>{

            callback(null,replys);
        }).catch((err)=>{
            callback(err);
        })
    }
}

const Reply = mongoose.model('reply',ReplySchema);
module.exports = Reply;
